import { cloneDeep } from 'lodash';
import regions from '@/components/common/region/final.json'
import { nullC } from '@/util/common';

/**
*@Author: QWP
*@Description: 获取所选择的地区的汉字
*@Params: value: 选中的地区id     isFinal: 是否只取最后一级显示
*@Date 2024-10-16 18:31
*/
export const getRegionLabel = (value: string, isFinal: boolean = false): string => {
  let values = value.split('/')
  let results: any = [], equlData: any = null;
  let currntIndex = 0;
  values.forEach(val => {
    if(currntIndex == values.length) {
      return
    }
    let info = (equlData || regions).find((i: any) => i.id == val) || {}
    results.push(info)
    equlData = info['children'] || []
    currntIndex += 1
  })
  return isFinal == false ? results.map((i: any) => i.name).join('/') : nullC(results[results.length - 1]['name'])
}